﻿using Dapper;
using System.Data.SqlClient;
using System.Linq;
using Ct.StudentProject.Myself;
using System.Data;
using System.Configuration;

namespace Ct.StudentProject.Data
{
    public class StudentDatabase
    {
        public static SqlConnection SqlConnection()
        {
            string sqlconnectionString = ConfigurationManager.ConnectionStrings["connectionString"].ConnectionString;
            var connection = new SqlConnection(sqlconnectionString);
            connection.Open();
            return connection;
        }

        public bool InsertStudent(student stu,out string msg)
        {
            using (IDbConnection conn = new SqlConnection())
            {
                string query = "INSERT INTO stu_info(userName,name,passWord,IDNumber)VALUES(@userName,@name,@passWord,@IDNumber)";
                conn.Execute(query, new { @userName = stu.userName, @name = stu.name, @passWord = stu.Password, @IDnumber = stu.IDNumber });
                query = "SELECT * FROM stu_info WHERE name = @name";
                student stu1 = conn.Query<student>(query, new { name = stu.name }).SingleOrDefault();
                msg = stu1.ID.ToString();
              //  MessageBox.Show("注册成功 您的ID是" + stu1.ID.ToString());
                return true;
            }
        }
        

    }
}


//var conn = new SqlConnection(ConfigurationManager.ConnectionStrings["SqlDiagnosticsDb"].ConnectionString)